package com.huidao.service;

import java.util.List;

import com.huidao.dao.ShoppingcartDao;
import com.huidao.dao.ShoppingcartDaoImpl;
import com.huidao.entity.Goods;
import com.huidao.entity.Shoppingcart;
import com.sun.org.apache.regexp.internal.recompile;

public class ShoppingcartServiceImpl implements ShoppingcartService {
	ShoppingcartDao dao=new ShoppingcartDaoImpl();
    int pageSize=100;
     
	@Override
	public String addShoppingcart(Shoppingcart shoppingcart) {
		// TODO Auto-generated method stub
		if(dao.addShoppingcart(shoppingcart)){
			return"";
		}else{
			return"添加购物车失败";
			
		}
	}

	@Override
	public String delShoppingcart(Long id) {
		// TODO Auto-generated method stub
		if(dao.delShoppingcart(id)){
			return"";
		}else{
			return"删除购物车失败";
		}
	}

	@Override
	public String delAllShoppingcart() {
		// TODO Auto-generated method stub
		if(dao.delAllShoppingcart()){
			return "";
		}else{
			return"删除总的购物车失败";
		}
	}

	@Override
	public String updateShoppingcart(Shoppingcart shoppingcart) {
		// TODO Auto-generated method stub
		if(dao.updateShoppingcart(shoppingcart)){
			return"";
		}else{
			return"修改购物车失败";
		}
	}

	@Override
	public List<Shoppingcart> getAllListPage(int currentPage,
			Long id) {
		// TODO Auto-generated method stub
		return dao.getAllListPage(currentPage, pageSize, id);
	}

	@Override
	public int getTotalCount() {
		// TODO Auto-generated method stub
		int count=dao.getTotalCount();
		if(count%pageSize==0){
			return count/pageSize;
		}else{
			return count/pageSize+1;
		}

	}

	@Override
	public String getUserShopnameByGoodsId(Long goodsid) {
		// TODO Auto-generated method stub
		return dao.getUserShopnameByGoodsId(goodsid);
	}

	@Override
	public String clearShoppingcart(Long id) {
		// TODO Auto-generated method stub
		if (dao.clearShoppingcart(id)) {
			return "";
		} else {
			return "清空失败";
		}
	}

}
